/* jaDTi package - v0.6.1 */
package grex.DT.Test;

import grex.Data.ArffTableModel;
import grex.DT.io.DecisionTreeToDot;
import grex.DT.io.ItemSetReader;
import grex.DT.tree.AttributeSet;
import grex.DT.tree.DecisionTree;
import grex.DT.tree.Item;
import grex.DT.tree.ItemSet;
import grex.DT.tree.KnownSymbolicValue;
import grex.DT.tree.SymbolicAttribute;

import java.io.IOException;
import java.io.Serializable;
import java.util.Vector;


/*
 * A short example program of the jaDTi library.
 */
public class ZooTest implements Serializable {

    final static String dbFileName = "zoo.db";
    final static String jadtiURL = "http://www.run.montefiore.ulg.ac.be/" +
            "~francois/software/jaDTi/";

    static public void main(String[] args)
            throws IOException {

        ItemSet learningSet = null;

        ArffTableModel arff = new ArffTableModel("iris.arff", 5, 1);        
        learningSet = ItemSetReader.readTrainSet(arff.getTrainFoldAsString("F1"));
        AttributeSet attributeSet = learningSet.attributeSet();

        Vector testAttributesVector = new Vector();
        int nrOfCols = arff.getNrOfCategorialColumns()+arff.getNrOfContinousColumns();
        for(int c=0;c<nrOfCols;c++)
            testAttributesVector.add(attributeSet.attribute(c));

        AttributeSet testAttributes = new AttributeSet(testAttributesVector);
        SymbolicAttribute goalAttribute =
                (SymbolicAttribute) learningSet.attributeSet().attribute(nrOfCols);

        DecisionTree tree = buildTree(learningSet, testAttributes,
                goalAttribute);

        //printDot(tree);
        System.out.println(tree);
//	printGuess(learningSet.item(0), tree);
    }

    /*
     * Build the decision tree.
     */
    static private DecisionTree buildTree(ItemSet learningSet,
            AttributeSet testAttributes,
            SymbolicAttribute goalAttribute) {
      /*  DecisionTreeBuilder builder =
                new DecisionTreeBuilder(learningSet, testAttributes,
                goalAttribute);

        return builder.build().decisionTree();*/
        return null;
    }


    /*
     * Prints a dot file content depicting a tree.
     */
    static private void printDot(DecisionTree tree) {
        System.out.println((new DecisionTreeToDot(tree)).produce());
    }


    /*
     * Prints an item's guessed goal attribute value.
     */
    static public void printGuess(Item item, DecisionTree tree) {
        AttributeSet itemAttributes = tree.getAttributeSet();
        SymbolicAttribute goalAttribute = tree.getGoalAttribute();

        KnownSymbolicValue goalAttributeValue =
                (KnownSymbolicValue) item.valueOf(itemAttributes, goalAttribute);
        KnownSymbolicValue guessedGoalAttributeValue =
                tree.guessGoalAttribute(item);

        String s = "Item goal attribute value is " +
                goalAttribute.valueToString(goalAttributeValue) + "\n";

        s += "The value guessed by the tree is " +
                tree.getGoalAttribute().valueToString(guessedGoalAttributeValue);

        System.out.println(s);
    }
}
